package com.Yukiha.gachamod.gachaMenu.client;

import com.Yukiha.gachamod.gachaMenu.client.gui.GachaBookMenu;
import com.Yukiha.gachamod.gachaMenu.client.gui.GachaBookScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "gachamod", value = Dist.CLIENT)
public class ClientModEvents {

    @SubscribeEvent
    public static void onClientTick(TickEvent.ClientTickEvent event) {
        // 只在客户端 Tick 的 END 阶段处理，确保玩家存在
        if (event.phase != TickEvent.Phase.END) return;

        Minecraft mc = Minecraft.getInstance();
        if (mc.player == null) return;

        // 兼容两种按键注册方式（你有两个不同命名的按键绑定）
//        boolean openBookPressed =
//                (ModKeyBindings.OPEN_GACHA_BOOK != null && ModKeyBindings.OPEN_GACHA_BOOK.consumeClick()) ||
//                        (ModClient.OPEN_BOOK_KEY != null && ModClient.OPEN_BOOK_KEY.consumeClick());

//        if (openBookPressed) {
//            Inventory inv = mc.player.getInventory();

//            // 如果你希望用 UUID 创建真实数据的菜单（推荐）
//            GachaBookMenu menu = new GachaBookMenu(0, inv, mc.player.getUUID());
//
//            // 如果你是客户端测试环境，想用伪数据，可用这个（不推荐）：
//            // GachaBookMenu menu = new GachaBookMenu(0, inv); // 需要你写个假数据构造函数
//
//            mc.setScreen(new GachaBookScreen(menu, inv, Component.literal("抽卡图鉴")));

    }


    @SubscribeEvent
    public static void onRegisterKeys(RegisterKeyMappingsEvent event) {
//        event.register(ModClient.OPEN_BOOK_KEY);
    }

//    @SubscribeEvent
//    public static void onRegisterKeybinds(RegisterKeyMappingsEvent event) {
//        ModKeyBindings.register(event);
//    }

}
